//
//  UserBrandController.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/29.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "UserBrandController.h"
#import "UserArrowItem.h"
#import "UserSaveItem.h"
#import "UserLabelItem.h"
#import "UserGroup.h"
#import "UserSericesChildVC.h"

@interface UserBrandController ()

@end

@implementation UserBrandController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadTableViewDataSource];
    
}


- (void)loadTableViewDataSource {
    
    NSArray *brandAndModelArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RacketBrandAndModel.plist" ofType:nil]];
    UserGroup *group0 = [[UserGroup alloc] init];
    
    group0.headHeight = kAutoHei(24);
    
    UserLabelItem *item0_0 = [UserLabelItem itemWithTitle:NSLocalizedString(@"User.Generic", nil)];
    [group0.items addObject:item0_0];
    
    __weak typeof(self) weakSelf = self;
    
    [brandAndModelArray enumerateObjectsUsingBlock:^(NSDictionary *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UserArrowItem *arrowItem = [UserArrowItem itemWithTitle:obj[@"RacketBrand"]];
        __weak typeof(arrowItem) weakArrowSelf = arrowItem;
        
        [arrowItem setBlock:^{
            UserSericesChildVC *childVc = [[UserSericesChildVC alloc] init];
            childVc.childType = SericesChildBrandAndModle;
            childVc.content = weakArrowSelf.title;
            [childVc.groups addObject:[weakSelf racketModelArray:obj[@"RacketModel"]]];
            
            [weakSelf.navigationController pushViewController:childVc animated:YES];
        }];
        
        [group0.items addObject:arrowItem];
        
    }];
    
    [self.groups addObject:group0];
}

- (UserGroup *)racketModelArray:(NSArray *)stringArr {
    
    UserGroup *group0 = [[UserGroup alloc] init];
    
    group0.headHeight = kAutoHei(24);
    
    [stringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UserSaveItem *saveItem = [UserSaveItem itemWithTitle:obj];
        [group0.items addObject:saveItem];
    }];
    
    return group0;
}



@end
